package com.sunagy.demand.front.service.impl;

import com.sunagy.demand.front.VO.CustomerUserBindVo;
import com.sunagy.demand.front.dataobject.CustomerUser;
import com.sunagy.demand.front.dataobject.CustomerUserInfo;
import com.sunagy.demand.front.repository.CustomerUserInfoRepository;
import com.sunagy.demand.front.service.CustomerUserInfoService;
import com.sunagy.demand.front.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * desc：#TODO fill me ！
 * author：三餘無夢生
 * date：2018/5/22
 * time：下午4:26
 */
@Service
public class CustomerUserInfoServiceImpl implements CustomerUserInfoService {

    @Autowired
    private CustomerUserInfoRepository customerUserInfoRepository;
    @Override
    public CustomerUserInfo add(CustomerUserBindVo customerUserBindVo,CustomerUser customerUser) {
        CustomerUserInfo customerUserInfo = new CustomerUserInfo();
        BeanUtil.copyProperties(customerUserInfo,customerUserBindVo);
        customerUserInfo.setCustomerUserId(customerUser.getId());
        customerUserInfo.setPhone(customerUser.getPhone());
        customerUserInfo.setEnable(customerUser.getEnable());
        customerUserInfo.setUsername(customerUser.getUsername());
        customerUserInfo = customerUserInfoRepository.save(customerUserInfo);
        return customerUserInfo;
    }

    @Override
    public CustomerUserInfo getByCustomerUserId(Integer customerUserId) {
        CustomerUserInfo customerUserInfo = customerUserInfoRepository.findByCustomerUserId(customerUserId);
        return customerUserInfo;
    }

    @Override
    public List<CustomerUserInfo> getAll() {
        return customerUserInfoRepository.findAll();
    }
}
